package jwd.base

import android.annotation.SuppressLint
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

/**
 * Created by udi on 17-7-29.
 */
open class BaseFragment @SuppressLint("ValidFragment") constructor(var fragementId: Int = 0) : Fragment() {


    init {
        var args = Bundle();
        this.arguments = args;
    }

    var inflater: LayoutInflater? = null
    var container: ViewGroup? = null

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {

        this.inflater = inflater
        this.container = container

        // Inflate the layout for this fragment
        if (this.fragementId == 0) {
            return null
        }

        return inflater!!.inflate(this.fragementId, container, false)
    }

    fun alert(msg: String, title: String = "", buttonName: String = ""): AlertDialog {
        return AlertDialog.Builder(this.activity)
                .setTitle(if (title.isBlank()) "提示" else title)
                .setMessage(msg)
                .setPositiveButton(if (buttonName.isBlank()) "确定" else buttonName, null)
                .show();
    }
}